<template>
  <el-dialog :model-value="visible" width="60%" @close="cancel" append-to-body top="10vh" class="el-dialog__wrapper1" :show-close="false">
    <div class="boardBox">
      <div class="left_box flex flex-1 box-row-column">
        <div class="zi1">{{ title }}</div>
        <div class="flex flex-1 box-row-column ggpad20 constent_box">
          <div class="flex box-row-column">
            <div class="bt_title1">风险点</div>
            <div class="flex-container">
              <div :class="checkid == item.id ? 'flex-item cursor on font15' : 'flex-item cursor font15'" v-for="item in dialoginfo" :key="item.id" @click="changeinfo(item)">{{ item.title }}</div>
            </div>
          </div>

          <div class="flex box-row-column mt10">
            <div class="bt_title2">风险提示</div>
            <div class="flex-container font15 contenthtml" v-html="infoArr.describe"></div>
          </div>

          <div class="flex box-row-column mt20">
            <div class="bt_title3">解决方案</div>
            <div class="flex-container  font15 contenthtml" v-html="infoArr.content"></div>
          </div>

          <div class="flex box-row-column mt20">
            <div class="bt_title4">案例及分析</div>
            <div class="flex-container  font15contenthtml" v-html="infoArr.TemCase"></div>
          </div>
          <div class="flex box-row-column mt20">
            <div class="bt_title4">引用法律依据</div>
            <div class="flex-container font15 contenthtml" v-html="infoArr.legal_content"></div>
          </div>
        </div>
      </div>
      <div class="right_box flex box-row-column">
        <div class="zi1">关联合同模板</div>
        <div class="flex flex-1 box-row-column mt20">
          <div class="flex box-row-column box-align-center cursor" v-for="item in infoArr.contract" :key="item.id" @click="godetail(item)">
            <div class="ht_img"><img :src="item.picture" alt="" /></div>
            <div class="mt10 ht_title">{{ item.contract_name }}</div>
          </div>
        </div>
      </div>

      <div style="font-size: 20px" @click="cancel()">
        <!-- 由于SVG图标默认不携带任何属性 -->
        <!-- 你需要直接提供它们 -->
        <CircleCloseFilled style="width: 1.5em; height: 1.5em; margin-left: 18px; cursor: pointer; color: #333" />
      </div>
    </div>
  </el-dialog>
</template>
<script setup lang="ts">
  import { ref, reactive, watch, onMounted } from "@/TUIKit/adapter-vue";
  import { createDepartment, Departmentedit } from "@/api/cf";
  import { ElMessage } from "element-plus";
  import router from "@/router";
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },

    dialoginfo: {
      type: Array,
      default: [],
    },
    title: {
      type: String,
      default: "",
    },
  });
  const infoArr = ref({});
  const rules = reactive({
    name: [{ required: true, message: "请输入部门名称", trigger: "blur" }],
  });
  const checkid = ref(0);

  const queryParams = ref({ parent_name: "", parent_id: "", name: "", id: "" });
  const emit = defineEmits<{ (event: "update:visible", value: boolean): void; (event: "success", value: ""): void }>();

  // 监听 localValue 的变化，通知父组件更新值
  watch(
    () => props.dialoginfo,
    newValue => {
      infoArr.value = newValue[0];
      checkid.value = newValue[0].id;
    });
  watch(
    () => props.visible,
    newValue => {
      if (newValue) {
      }
    }
  );

  onMounted(() => {});

  function cancel() {
    emit("update:visible", false);
    emit("success", "");
  }

  function changeinfo(item) {
    checkid.value = item.id;

    infoArr.value = item;
  }
  function godetail(item) {
    const url = item.file_path;
    router.push({
      path: "/urldetail",
      query: { url }, // 传递查询参数
    });
    //  router.push({ name: "urldetail",params:{ url: item.file_path} });
  }

  // 获取表单引用
  const queryForm = ref(null);

  function submitForm() {
    /// console.log(props.edit_info, "sgsgsgsg");
    queryForm.value.validate(valid => {
      if (valid) {
        const data = {
          name: queryParams.value.name,
          parent_id: queryParams.value.parent_id,
          parent_name: queryParams.value.parent_name,
          id: queryParams.value.id ? queryParams.value.id : "",
        };

        // if(props.edit_info){
        //   console.log(2222,"data");
        // }else{
        //   console.log(444444,"data");
        // }
        const tmp = props.isedit === 3 ? Departmentedit : createDepartment;

        tmp(data)
          .then(res => {
            ElMessage({
              message: res.msg,
              grouping: true,
              type: "success",
            });
            emit("update:visible", false);
            emit("success", "");
          })
          .catch(err => {
            ElMessage({
              message: err,
              grouping: true,
              type: "error",
            });
          });
      } else {
        console.log("表单验证失败");
        return false;
      }
    });

    // 在这里处理表单提交逻辑，例如发送请求到服务器

    // 通知父组件更新 visible 为 false
    // emit("update:visible", false);
    // emit("update:visible", false);
    //
  }
</script>
<style>
.el-dialog__wrapper1 {
  background-color: rgba(0, 0, 0, 0) !important;
  box-shadow: none !important;
  /* 完全透明 */
}
</style>
<style lang="scss" scoped>
.boardBox {
  display: flex;
  // align-items: center;
  // flex-direction: column;
  // flex-wrap: wrap;
  // justify-content: space-around;
  overflow: hidden;
  height: 100%;

  &::-webkit-scrollbar {
    display: none;
  }

  -ms-overflow-style: none;
  scrollbar-width: none;

  .tishi {
    font-size: 14px;
    color: #999;
    background-color: #f3f8fb;
    padding: 5px 10px;
    border-radius: 6px;
  }

  .left_box {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    overflow-y: scroll;
  }

  .right_box {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    width: 20%;
    overflow-y: scroll;
    margin-left: 20px;
  }

  .zi1 {
    font-size: 18px;
    // font-family: 黑体;
    font-weight: 500;
    padding: 10px 0;
    border-bottom: solid 1px #eaeaea;
  }

  .bt_title1 {
    font-size: 16px;
    background: url(@/assets/image/cf/img05.png) no-repeat center left;
    background-size: 17px;
    padding-left: 20px;
    margin-bottom: 10px;
  }

  .bt_title2 {
    font-size: 16px;
    background: url(@/assets/image/cf/img06.png) no-repeat center left;
    background-size: 17px;
    padding-left: 20px;
    margin-bottom: 10px;
  }

  .bt_title3 {
    font-size: 16px;
    background: url(@/assets/image/cf/img07.png) no-repeat center left;
    background-size: 17px;
    padding-left: 20px;
    margin-bottom: 10px;
  }

  .bt_title4 {
    font-size: 16px;
    background: url(@/assets/image/cf/img08.png) no-repeat center left;
    background-size: 18px;
    padding-left: 20px;
    margin-bottom: 10px;
  }

  .ht_img img {
    width: 100%;
    height: 200px;
  }

  .contenthtml {
    line-height: 25px;

  }

  .flex-container {
    display: flex;
    /* 启用Flexbox */
    flex-wrap: wrap;
    /* 允许子项换行 */
    justify-content: flex-start;
    /* 子项在主轴上的对齐方式 */
    align-items: stretch;

    /* 子项在交叉轴上的对齐方式 */
  }

  .flex-item {
    /* 根据需要设置宽度或其他样式 */
    margin: 5px;
    padding: 5px 8px;
    border: solid 1px #eaeaea;
    border-radius: 5px;
    /* 可选：添加一些间距 */
  }

  .ht_title {
    font-size: 12px;
  }

  .constent_box {
    overflow-y: scroll;
    max-height: calc(60vh);
  }

  .on {
    border-color: #01509f;
    color: #01509f;
  }
}
</style>
